package huang.com.android.intentreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

/**
 * Created by hwang on 2018/5/25.
 */

public class SMSReceiverActivity extends BroadcastReceiver{

    private static final String TAG = "onReceive";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG,"onReveive-->running");

        //接受Intent对象当中的数据
        Bundle bundle = intent.getExtras();

        Object[] myOBJpdus = (Object[]) bundle.get("pdus");

        SmsMessage[] messages = new SmsMessage[myOBJpdus.length];
        System.out.println(messages.length);
        for (int i = 0;i < myOBJpdus.length;i++){
            //使用Object数组当中的对象创建SmsMessage对象
            messages[i] = SmsMessage.createFromPdu((byte[]) myOBJpdus[i]);

            System.out.println(messages[i].getDisplayMessageBody());

        }
    }
}
